home *** CD-ROM | disk | FTP | other *** search
- unit CmdTest32U;
-
- {$ifdef Ver80} { Delphi 1.0x }
- {$define DelphiLessThan3}
- {$endif}
- {$ifdef Ver90} { Delphi 2.0x }
- {$define DelphiLessThan3}
- {$define DelphiLessThan4}
- {$define DelphiLessThan5}
- {$endif}
- {$ifdef Ver93} { C++ Builder 1.0x }
- {$define DelphiLessThan3}
- {$define DelphiLessThan4}
- {$define DelphiLessThan5}
- {$endif}
- {$ifdef Ver100} { Delphi 3.0x }
- {$define DelphiLessThan4}
- {$define DelphiLessThan5}
- {$endif}
- {$ifdef Ver110} { C++ Builder 3.0x }
- {$define DelphiLessThan4}
- {$define DelphiLessThan5}
- {$endif}
- {$ifdef Ver120} { Delphi 4.0x }
- {$define DelphiLessThan5}
- {$endif}
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls;
-
- type
- TForm1 = class(TForm)
- Button1: TButton;
- ListBox1: TListBox;
- Edit1: TEdit;
- procedure Button1Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- {$ifdef DelphiLessThan3}
- procedure Win32Check(RetVal: Bool);
- begin
- if not RetVal then
- raise Exception.Create(SysErrorMessage(GetLastError))
- end;
- {$endif}
-
- procedure TForm1.Button1Click(Sender: TObject);
- var
- SI: TStartupInfo;
- PI: TProcessInformation;
- ComSpec: array[0..MAX_PATH] of Char;
- CmdLine: String;
- begin
- GetEnvironmentVariable('COMSPEC', ComSpec, SizeOf(ComSpec));
- CmdLine := String(ComSpec) + ' /C ' + Edit1.Text;
- GetStartupInfo(SI);
- Win32Check(
- CreateProcess(
- nil, PChar(CmdLine), nil, nil,
- False, 0, nil, nil, SI, PI));
- WaitForInputIdle(PI.hProcess, Infinite);
- WaitForSingleObject(PI.hProcess, Infinite);
- ListBox1.Items.LoadFromFile('C:\DirList.Txt')
- end;
-
- end.
-